package com.ruoyi.mapper;

import com.ruoyi.domain.AdvOrders;
import com.ruoyi.domain.AdvOrdersdetail;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * Mapper接口
 *
 * @author ruoyi
 * @date 2024-05-13
 */
public interface AdvOrdersdetailMapper
{

    @Delete("delete from  adv_ordersdetail " +
            "where  adv_orders_id in " +
            "(select  adv_orders_id from  adv_orders)")
    public int clear();

    @Delete("delete from  adv_ordersdetail " +
            "where  adv_orders_id in " +
            "(select  adv_orders_id from  adv_orders  where   adv_members_id=#{advMembersId})")
    public int deleteByAdvMembersId(@Param("advMembersId") String advMembersId);
    /**
     * 查询
     *
     * @param advOrdersdetailId 主键
     * @return
     */
    public AdvOrdersdetail selectAdvOrdersdetailByAdvOrdersdetailId(Long advOrdersdetailId);


    /**
     * 通用查询
     * @param advOrdersdetail
     * @return
     */
    public List<AdvOrdersdetail> selectAdvOrdersdetailList(AdvOrdersdetail advOrdersdetail);


    public List<AdvOrdersdetail> selectAdvOrdersdetailListApp(@Param("advOrdersId") Long ordersId, @Param("advProductsId") Long advProductsId);

    /**
     * 新增
     *
     * @param advOrdersdetail
     * @return 结果
     */
    public int insertAdvOrdersdetail(AdvOrdersdetail advOrdersdetail);

    /**
     * 修改
     *
     * @param advOrdersdetail
     * @return 结果
     */
    public int updateAdvOrdersdetail(AdvOrdersdetail advOrdersdetail);

    /**
     * 删除
     *
     * @param advOrdersdetailId 主键
     * @return 结果
     */
    public int deleteAdvOrdersdetailByAdvOrdersdetailId(Long advOrdersdetailId);

    /**
     * 批量删除
     *
     * @param advOrdersdetailIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteAdvOrdersdetailByAdvOrdersdetailIds(Long[] advOrdersdetailIds);

    /**
     *  硬件订单明细
     * @param advOrdersId
     * @return
     */
    List<AdvOrdersdetail> selectOrderByMore(Long advOrdersId);

    /**
     *  内容订单明细
     * @param advOrdersId
     * @return
     */
    List<AdvOrdersdetail> selectOrderByMoreTwo(Long advOrdersId);

    @Select("select adv_membersaddr_id from adv_membersaddr where recv_default = '1' and adv_members_id = #{advMembersId}")
    Long getDefaultAddressId(@Param("advMembersId") Long advMembersId);

    void updateSyncFlagToOneByProductId(Long[] productIds, String weOpenid);

    void updateSyncFlagToZeroByWeOpenid(String weOpenid);

    List<AdvOrdersdetail> findBuy(@Param("advMembersId") Long advMembersId);

    void removeSyncProduct(@Param("advMembersId") String advMembersId);

    int syncProduct(@Param("advMembersId") String advMembersId, @Param("advProductIds") Long[] advProductIds);

    /**
     * 根据订单id查询订单明细记录条数
     * @param advOrdersId
     * @return
     */
    int selectOrderCountById(@Param("advOrdersId") Long advOrdersId);

    /**
     * 根据订单id查询出入库记录条数
     * @param advOrdersId
     * @return
     */
    int selectOutInCountById(@Param("advOrdersId") Long advOrdersId);

    //更新订单数量
    void updateOrdersNum(AdvOrders advOrders);

    List<AdvOrdersdetail> queryProductList(AdvOrdersdetail advOrdersdetail);

    @Delete("delete from adv_ordersdetail where adv_orders_id = #{advOrdersId} and " +
            "adv_products_id = #{advProductId}")
    int deleteByOrderIdAndProductId(@Param("advOrdersId") Long advOrdersId,
                                    @Param("advProductId") Long advProductId);

    List<AdvOrdersdetail> selectOrderByMoreThree(Long advOrdersId);
}
